package data

import (
	"context"
	"github.com/go-kratos/kratos/v2/log"
	"go.opentelemetry.io/otel"
	"go.opentelemetry.io/otel/trace"
	"kratos_cron_task/internal/biz"
	"time"
)

type CronRepo struct {
	data   *Data
	logger *log.Helper
}

func NewCronRepo(data *Data, logger log.Logger) biz.CronInterface {
	return &CronRepo{
		data:   data,
		logger: log.NewHelper(logger, log.WithMessageKey("cronRepo")),
	}
}

func (c *CronRepo) CronTest1(ctx context.Context) error {
	ctx, span := otel.Tracer("Data").Start(ctx, "CronTest1Data", trace.WithSpanKind(trace.SpanKindInternal))
	defer span.End()

	return c.data.Redis.Set(ctx, "name1", "whw1", time.Hour).Err()
}

func (c *CronRepo) CronTest2(ctx context.Context) error {
	ctx, span := otel.Tracer("Data").Start(ctx, "CronTest2Data", trace.WithSpanKind(trace.SpanKindInternal))
	defer span.End()

	return c.data.Redis.Set(ctx, "name2", "whw2", time.Hour).Err()
}
